(function () {

  'use strict';

  angular
  .module('app')
  .controller('PigInfoController', PigInfoController);

  PigInfoController.$inject = ['$scope', '$http', '$stateParams', 'API', 'AppAuthenticationService', '$state'];

  function PigInfoController($scope, $http, $stateParams, API, AppAuthenticationService, $state) {

      var pig_id = $stateParams.pig_id;
      // pig_id = 'mTwWxBcvzZg=';
      $scope.product = null;
      $scope.quarantine = null;

      $scope.isLoading = false;
      $scope.isLoaded = false;

      function _reload() {
          $scope.isLoading = true;

          if ( !AppAuthenticationService.getToken() ) {
              // $state.go('wechat-auth', {});
              // return;
          }

          API.goods.getOnePig({pig_id:pig_id}).then(function(pig){
              $scope.isLoaded = true;
              $scope.product = pig;
              if (pig.pig_quarantine_detail) {
                  $scope.quarantine = pig.pig_quarantine_detail;
              }
          });
      }

      _reload();
      
  }

})();
